package com.vzoom.logdesensitization.util;

import com.vzoom.logdesensitization.DesensitizationStrategy;
import com.vzoom.logdesensitization.config.DesensitizationStrategyHolder;

import java.util.List;
import java.util.Map;

public class MapTransforms {

    public static void reverseMap(Map<String, List<String>> origin, Map<String, String> destination) {
        Map<String, DesensitizationStrategy> staticStrategyMap = DesensitizationStrategyHolder.getStaticStrategyMap();
        for (Map.Entry<String, List<String>> stringListEntry : origin.entrySet()) {
            String value = stringListEntry.getKey();
            List<String> list = stringListEntry.getValue();
            for (String newKey : list) {
                if (staticStrategyMap.containsKey(value)) {
                    destination.put(newKey, value);
                }
            }
        }
    }

    public static void reverseMapIgnoreCase(Map<String, List<String>> origin, Map<String, String> destination) {
        Map<String, DesensitizationStrategy> staticStrategyMap = DesensitizationStrategyHolder.getStaticStrategyMap();
        for (Map.Entry<String, List<String>> stringListEntry : origin.entrySet()) {
            String value = stringListEntry.getKey();
            List<String> list = stringListEntry.getValue();
            for (String newKey : list) {
                if (staticStrategyMap.containsKey(value)) {
                    destination.put(newKey.toLowerCase(), value);
                }
            }
        }
    }
}
